# $LastChangedDate: 2011-09-09 00:10:19 -0400 (Fri, 09 Sep 2011) $
# LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG
# Find OpenSceneGraph.
# Output:
# OPENTHREADS_FOUND
# OPENTHREADS_INC_DIR
# OPENTHREADS_LIBS
# Notes:
# - See module.txt.
#-------------------------------------------------------------------------------

INCLUDE( CMakeModules/inc_find.cmake )

#-------------------------------------------------------------------------------
# Find include directory : OPENTHREADS_INC_DIR

FIND_PATH( OPENTHREADS_INC_DIR
    NAMES OpenThreads/Thread
    PATHS $ENV{OPENTHREADS_INCLUDE_DIR}
          $ENV{OPENTHREADS_DIR}/include
          $ENV{OPENTHREADS_DIR}
          $ENV{OPENTHREADS_INC_DIR}
          ${POSSIBLE_OSG_INC_DIRS}  # OSG provides OpenThreads
          ${POSSIBLE_INC_DIRS}
)

#-------------------------------------------------------------------------------
# Find libraries : OPENTHREADS_LIBS

FIND_LIBRARY( OPENTHREADS_LIBS
    NAMES OpenThreads
    PATHS $ENV{OPENTHREADS_LIBRARY_DIR}
          $ENV{OPENTHREADS_DIR}/lib64
          $ENV{OPENTHREADS_DIR}/lib
          $ENV{OPENTHREADS_DIR}
          $ENV{OPENTHREADS_LIB_DIR}
          ${POSSIBLE_OSG_LIB_DIRS}  # OSG provides OpenThreads
          ${POSSIBLE_LIB_DIRS}
)

#-------------------------------------------------------------------------------
# Found everything?

IF( OPENTHREADS_INC_DIR AND OPENTHREADS_LIBS )
    SET( OPENTHREADS_FOUND "TRUE" )
    # Apply.
    ADD_SYSTEM_INCLUDE_DIR( ${OPENTHREADS_INC_DIR} )
ELSE()
    MESSAGE( FATAL_ERROR "Could not find OpenThreads" )
ENDIF()
